<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组合式api</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        h2 {
            color: blue;
        }
        button {
            background-color: #4caf50;
            color: white;
            padding: 10px;
            border: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="应用"></div>
    <script type="module">
        const {createApp, ref} = Vue 
        
        const 应用 = {
            template: /*html*/ `
                <div>
                    <h2>{{标题}}</h2>
                    <p>{{消息}}</p>
                    <button @click="增加计数">增加计数</button>
                    <div>计数: {{计数器}}</div>
                </div>
            `,
            setup() {
                name: '我的组件'
                const 标题 = '欢迎使用 vue3 组合式api'
                const 消息 = '这是一个简单的组件示例'
                const 计数器 = ref(0)

                const 增加计数 = () => {
                    计数器.value ++
                }

                return {标题, 消息, 计数器, 增加计数}
            }
        }

        createApp(应用).mount('#应用')
    </script>
</body>
</html>